<%@page import="com.jfinal.kit.PropKit"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" import="cn.com.dashihui.web.common.OrderCode" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>公司管理</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
        <style type="text/css">
			
		</style>
</head>
<body>
<div id="wrapper"  class="row">
	
			<div class="col-lg-12">
				<h1 class="page-header">公司入驻</h1>
			</div>
		<!-- 搜索框 -->
			<div class="title-top col-lg-12">
				<label class="search-label">公司编号：</label><input type="text" id="sSellerId" value="" class="form-control search-input width100" maxlength="21">
				<label class="search-label">入驻时间：</label><input type="text" id="sBeginDate" value="" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
				<label class="search-label">至</label><input type="text" id="sEndDate" value="" class="form-control search-input width120 datetimepicker" data-format="yyyy-mm-dd" >
		
				<label class="search-label">公司电话：</label><input type="text" id="sTel" value="" class="form-control search-input width100" maxlength="21">
				<label class="search-label">公司状态：</label>
				<div class="search-input">
					<select id="sState" class="selectpicker" data-width="100">
						<option value="0">全部</option>
						<option value="1">审核中</option>
						<option value="2">入驻</option>
						<option value="3">已驳回</option>
						<option value="6">重新上线</option>
						<option value="7">升级中</option>
					</select>
				</div>
				<button class="btn btn-success search-btn" onclick="query();">确定</button>
				<button class="btn btn-success search-btn" onclick="reset();">重置</button>
					<shiro:hasPermission name="dict:seller:doExcel">
						<button onclick="doExcel();"  class="btn btn-success pull-right">导出</button>
						</shiro:hasPermission>
				<div class="clearfix"></div>
			</div>
			<div class="col-lg-12 title-top">
				<div class="col-lg-12">
						<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font> 条记录</div>
					
				</div>
				<div class="table-responsive panel panel-default" >
					<table class="table table-noellipsis table-bordered" style=" overflow:scroll;">
						<thead>
							<tr>
								<th width="200px;">操作</th>
								<th width="100px;">公司ID</th>
								<th width="150px;">公司名称</th>
								<th width="80px;">视频功能</th>
								<th width="150px;">入驻时间</th>
								<th width="100px;">公司联系人</th>
								<th width="100px;">联系电话</th>
								<th width="100px;">状态</th>
								<th width="180px;">入住审核时间</th>
							</tr>
						</thead>
						<tbody id="dataList"></tbody>
					</table>
				</div>
		        	<div class="col-lg-12">
	        			<div class = "pull-right">
		        			<div class="text-muted  pull-left" style="margin-top:20px; margin-right:18px;">
							<select id="pageSize" name="pageSize" class="selectpicker" data-width="100" onchange="query()" >
				    					<option value="10" selected = "selected">10条/页</option>
										<option value="15">15条/页</option>
										<option value="20">20条/页</option>
										<option value="50">50条/页</option>
										<option value="100">100条/页</option>
				    				</select>
							</div>
			        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
			        	</div>
	        	</div>
			</div>
	
</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 
<shiro:hasPermission name="dict:seller:toCancel">
								<a href="javascript:toDrop('{{item.sellerId}}');"><span class="btn">降权</span></a>
							</shiro:hasPermission>

-->
<script type="text/html" id="dataTpl">
	{{each list as item}}
				<tr id="item{{item.id}}" data-id="{{item.id}}">
					{{if item.state==1}}
						<td>
							<a href="javascript:showOrder('{{item.sellerId}}');"><span class="btn">详情</span></a>
						<shiro:hasPermission name="dict:seller:doAccept">
							<a href="javascript:doAccept('{{item.sellerId}}');"><span class="btn">通过</span></a>
						</shiro:hasPermission>
						<shiro:hasPermission name="dict:seller:toCancel">
							<a href="javascript:toCancel('{{item.sellerId}}');"><span class="btn">驳回</span></a>
						</shiro:hasPermission>
						</td>
					{{else if item.state==2}}
						<td>
							<a href="javascript:showOrder('{{item.sellerId}}');"><span class="btn">详情</span></a>
							<a href="javascript:doDown('{{item.sellerId}}');"><span class="btn">下线</span></a>
						</td>
					{{else if item.state==6}}
						<td>
							<a href="javascript:showOrder('{{item.sellerId}}');"><span class="btn">详情</span></a>
						<shiro:hasPermission name="dict:seller:doAccept">
							<a href="javascript:doAccept('{{item.sellerId}}');"><span class="btn">通过</span></a>
						</shiro:hasPermission>
						<shiro:hasPermission name="dict:seller:toCancel">
							<a href="javascript:toCancel('{{item.sellerId}}');"><span class="btn">驳回</span></a>
						</shiro:hasPermission>
						</td>
					{{else if item.state==7}}
						<td>
							<a href="javascript:showOrder('{{item.sellerId}}');"><span class="btn">详情</span></a>
						</td>	
					{{else if item.state==3 || item.state==5 || item.state==4}}
						<td>
							<a href="javascript:showOrder('{{item.sellerId}}');"><span class="btn">详情</span></a>
						</td>
					{{/if}}
					<td>{{item.sellerId}}</td>
					<td>{{item.sellerName}}</td>
					<td>{{item.video | flagTransform:0,'关闭',1,'开启'}}</td>	
					<td>{{item.createtime}}</td>
					<td>{{item.trueName}}</td>
					<td>{{item.contact}}</td>
					{{if item.state==1}}
						<td>入驻审核中</td>
					{{else if item.state==2}}
						<td>入驻</td>
					{{else if item.state==3}}
						<td>已驳回</td>
					{{else if item.state==4}}
						<td>下线</td>
					{{else if item.state==6}}
						<td>编辑待审核</td>
					{{else if item.state==7}}
						<td>升级中</td>
					{{/if}}
					<td>{{item.checktime}}</td>
					
				</tr>
	{{/each}}
</script>
<script type="text/javascript">
var dataPaginator;
$(query);
function query(){
	var pageSize=$("#pageSize").val();
	var params = {
		pageSize:pageSize,
		sellerId:$("#sSellerId").val(),
		beginDate:$("#sBeginDate").val(),
		endDate:$("#sEndDate").val(),
		tel:$("#sTel").val(),
		state:$("#sState").val()
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/dict/seller/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
	});
}
function reset(){
	$("#sSellerId").val("");$("#sBeginDate").val("");$("#sEndDate").val("");$("#sTel").val("");
	$("#sState").val("0");$("#sState").trigger("change"); 
}
var showSellerDialog;
function showOrder(sellerId){
	showSellerDialog = Kit.dialog("查看详情","${BASE_PATH}/dict/seller/detail?sellerId="+sellerId,{closable:true}).open();
}
 function onEditSuccess(newObject){
	$("#item"+newObject.id).replaceWith(template("dataTpl",{"list":[newObject]}));
} 
var toCancelDialog;
function toCancel(sellerId){
	toCancelDialog = Kit.dialog("驳回原因","${BASE_PATH}/dict/seller/toCancel?sellerId="+sellerId,{closable:true,size:"size-wide:100px"}).open();
}
function doCancel(sellerId){
	Kit.confirm("提示","确定要驳回入驻申请吗？",function(ref){
		$.post("${BASE_PATH}/dict/seller/doCancel",{'sellerId':sellerId},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
			
		});
	});
}


var toDropDialog;
function toDrop(sellerId){
	toDropDialog = Kit.dialog("驳回原因","${BASE_PATH}/dict/seller/toDrop?sellerId="+sellerId,{closable:true,size:"size-wide:100px"}).open();
}

function doAccept(sellerId){
	Kit.confirm("提示","确定要审核入驻申请吗？",function(ref){
		$.post("${BASE_PATH}/dict/seller/doAccept",{'sellerId':sellerId},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else if(result.flag==1){
				Kit.alert("此手机号已存在，请修改手机");return;
			}else{
				Kit.alert("操作失败");return;
			}
		});
	});
}
 
function doDelete(id,sellerId){
	Kit.confirm("提示","确定要删除商户吗？",function(ref){
		$.post("${BASE_PATH}/dict/seller/doDelete",{'sellerId':sellerId},function(result){
			if(result.flag==0){
				$("#item"+id).remove();
			}else{
				Kit.alert("删除失败");return;
			}
			
		});
	});
}
function doDown(sellerId){
	Kit.confirm("提示","下线商家会同步下线所有分公司以及对应商品",function(ref){
		$.post("${BASE_PATH}/dict/seller/doDown",{'sellerId':sellerId},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
		});
	});
}
function doExcel(){
	var sellerId = $("#sSellerId").val(),beginDate = $("#sBeginDate").val(), endDate = $("#sEndDate").val(), tel = $("#sTel").val(),state = $("#sState").val();
	window.location.href="${BASE_PATH}/dict/seller/doExcel?sellerId="+sellerId+"&beginDate="+beginDate+"&endDate="+endDate+"&tel="+tel+"&state="+state;
}
$("#sBeginDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    pickerPosition:'bottom-right',
    autoclose:true,
}).on("click",function(){
	var d2=new Date();
	var d=$("#sEndDate").val();
	if(d==""){
		 $("#sBeginDate").datetimepicker("setEndDate",d2);
	}else{
		var d1=new Date(d); 
		d1.setDate(d1.getDate()-1);
		if(d1>d2){
	  	 	 $("#sBeginDate").datetimepicker("setEndDate",d2);
		}else{
			 $("#sBeginDate").datetimepicker("setEndDate",d1);
		}
	}
});

$("#sEndDate").datetimepicker({
    format: 'yyyy-mm-dd hh:ii:ss',
    minuteStep:1,
    minView:'hour',
    language: 'zh-CN',
    autoclose:true,
	}).on("click",function(){
		var d=$("#sBeginDate").val();
		var d1=new Date(d); 
		d1.setDate(d1.getDate()+1); 
		$("#sEndDate").datetimepicker("setStartDate",d1);
	});
	
 $(document).on("click","#sEndDate",function(){
    	$('#sEndDate').datetimepicker('show');
    });

$(document).on("click","#sBeginDate",function(){
	$('#sBeginDate').datetimepicker('show');
});
</script>
</body>
</html>